package com.laxia.interceptor;

import com.laxia.exception.ensure.Ensure;
import com.laxia.model.UserSession;
import com.laxia.util.SessionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆校验
 *
 * @author weishuai
 * @since 2019-09-21
 */
@Component
@Slf4j
public class LoginValidInterceptor implements HandlerInterceptor {


    /**
     * 暂无用   实际usersessionInterceptor->loginValidateAspect
     *
     * @param request
     * @param response
     * @param handler
     * @return
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        UserSession currentUser = SessionUtil.getCurrentUser();
        Ensure.that(currentUser.isLogin()).isTrue("401");
        Ensure.that(currentUser.getStatus() == 0).isTrue("402");
        return true;
    }
}
